//
//  BasedViewController.m
//  FCHealthy
//
//  Created by mouxiaochun on 16/2/18.
//  Copyright © 2016年 mmc. All rights reserved.
//

#import "BasedViewController.h"
#import "MBProgressHUD.h"
#import "SVProgressHUD.h"

@interface BasedViewController()<UIGestureRecognizerDelegate>


@end



@implementation BasedViewController
- (void)viewDidLoad {

    [super viewDidLoad];
    
    self.view.backgroundColor = [UIColor whiteColor];
    self.navigationItem.leftBarButtonItem = self.leftBarItem;
    
   // [self addSubViews];
    
    
    _tapGr = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(hideKeyboardAction)];
    _tapGr.delegate = self;
    [self.view addGestureRecognizer:_tapGr];

    

#pragma mark解决界面上移的问题
    [self makeVCFromZero];

    
}
//-(void)addSubViews{
//    
//    [self.view addSubview:self.backBtn];//返回键
//
//
//}

//-(UIButton *)backBtn{
//    if (!_backBtn) {
//        _backBtn =[UIButton buttonWithType:UIButtonTypeCustom];
//        _backBtn.hidden = no;
//        _backBtn.frame = CGRectMake(10, 30, 20, 20);
//        [_backBtn setImage:[UIImage imageNamed:@"首页_线路分类_03"] forState:UIControlStateNormal];
//        [_backBtn setTitle:@"" forState:UIControlStateNormal];
//        [_backBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
//        [_backBtn addTarget:self action:@selector(_back) forControlEvents:UIControlEventTouchUpInside];
//
//    }
//    return _backBtn;
//    
//}
//-(void)_back{
//    [self.navigationController popViewControllerAnimated:YES];
//    
//}



-(void)xjSVRefresh:(NSString *)message{
    [SVProgressHUD showWithStatus:message maskType:SVProgressHUDMaskTypeGradient];
    
}
-(void)xjSVEndRefresh{
    [SVProgressHUD dismiss];
    
}
-(void)hideKeyboardAction{
    [self.view endEditing:YES];
}
-(void)makeVCFromZero{

    if ([[[UIDevice currentDevice]systemVersion]floatValue]>=7.0) {
        
        self.edgesForExtendedLayout = UIRectEdgeNone;
        
    }

}
-(void)viewWillDisappear:(BOOL)animated{
    [super viewWillDisappear:animated];
    [self.view endEditing:YES];

}
- (UIBarButtonItem *) leftBarItem {

    UIButton *bt = [UIButton buttonWithType:UIButtonTypeCustom];
    UIImage *image = [UIImage imageNamed:@"首页_线路分类_03@3x"];
    [bt setImage:image forState:UIControlStateNormal];
    [bt setImage:[UIImage imageNamed:@"首页_线路分类_03@3x"] forState:UIControlStateHighlighted];
    bt.frame = (CGRect){0,0,image.size};
    [bt addTarget:self action:@selector(goback) forControlEvents:UIControlEventTouchUpInside];
    
    if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7.0) {
        self.navigationController.interactivePopGestureRecognizer.enabled = YES;
        self.navigationController.interactivePopGestureRecognizer.delegate = self;
    }
    
    UIBarButtonItem *item = [[UIBarButtonItem alloc] initWithCustomView:bt];

    return item;
}

- (void) goback {

    [self.navigationController popViewControllerAnimated:YES];
}

#pragma marltableView和手势冲突的解决方法
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch{
    if ([touch.view isKindOfClass:[UITextField class]])
    {
        return NO;
    }
    // 若为UITableViewCellContentView（即点击了tableViewCell），则不截获Touch事件
   // NSLog(NSStringFromClass([touch.view class]));
    if ([NSStringFromClass([touch.view class]) isEqualToString:@"UITableViewCellContentView"]) {
        return NO;
    }
    return YES;
}
-(void)dealloc{
    [self.view removeGestureRecognizer:_tapGr];
}

#pragma mark
-(void)showHint:(NSString *)msg{
    
    [self hideHint];
    MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
    hud.mode = MBProgressHUDModeText;
    hud.labelFont = FONT(18);
    hud.detailsLabelFont = FONT(18);
    if (msg.length == 0) {
        //        msg = @"加载中...";
        hud.mode = MBProgressHUDModeIndeterminate;
    }
    hud.detailsLabelText = msg;
}
-(void)hideHint{
    
    [MBProgressHUD hideHUDForView:self.view animated:YES];
}
-(void)hideHintInterValTwoSecond{
    [self performSelector:@selector(hideHint) withObject:nil afterDelay:2.0];
}
-(void)hideHintInterVal:(double)second{
    [self performSelector:@selector(hideHint) withObject:nil afterDelay:second];
}

-(void)showHint:(NSString *)msg withMinite:(double)minite{
    [self showHint:msg];
    [self hideHintInterVal:minite];
}




@end
